package org.teamh.gui.ingame.effects;

import static org.lwjgl.opengl.GL11.*;

public class TextureShot extends ShotEffect{
	private static final float DURATION = 200;
	
	private int texture;
	
	public TextureShot(float startX, float startY, float startZ, float endX,
			float endY, float endZ, int texture) {
		super(startX, startY, startZ, endX, endY, endZ);
		
		this.texture = texture;
		
		setDuration(DURATION);
	}

	//	Vector3f right = new Vector3f(fMatrix.get(0), fMatrix.get(4), fMatrix.get(8));
	
	//Bei diesem Vektor drehen sich die Baeume auch mit, wenn man nach oben schaut
	//Vector3f up = new Vector3f(fMatrix.get(1), fMatrix.get(5), fMatrix.get(9));
	@Override
	public void render(float timeElapsed) {
		super.render(timeElapsed);
		
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture);
		
		glColor3f(1, 1, 1);
		
		glBegin(GL_QUADS);
		{
			float size = 1 / 64f;
			glTexCoord2f(1, 0);
			glVertex3f(getCurX() - getModelviewMatrix().get(0) * size + getModelviewMatrix().get(1) * size, 
					getCurY() - getModelviewMatrix().get(4) * size + getModelviewMatrix().get(5) * size, 
					getCurZ() - getModelviewMatrix().get(8) * size + getModelviewMatrix().get(9) * size);
			
			glTexCoord2f(1, 1);
			glVertex3f(getCurX() + getModelviewMatrix().get(0) * size + getModelviewMatrix().get(1) * size, 
					getCurY() + getModelviewMatrix().get(4) * size + getModelviewMatrix().get(5) * size, 
					getCurZ() + getModelviewMatrix().get(8) * size + getModelviewMatrix().get(9) * size);
			
			glTexCoord2f(0, 1);
			glVertex3f(getCurX() + getModelviewMatrix().get(0) * size - getModelviewMatrix().get(1) * size, 
					getCurY() + getModelviewMatrix().get(4) * size - getModelviewMatrix().get(5) * size, 
					getCurZ() + getModelviewMatrix().get(8) * size - getModelviewMatrix().get(9) * size);
			
			glTexCoord2f(0, 0);
			glVertex3f(getCurX() - getModelviewMatrix().get(0) * size - getModelviewMatrix().get(1) * size, 
					getCurY() - getModelviewMatrix().get(4) * size - getModelviewMatrix().get(5) * size, 
					getCurZ() - getModelviewMatrix().get(8) * size - getModelviewMatrix().get(9) * size);
		}
		glEnd();
		
//		glEnable(GL_TEXTURE_2D);
//		glEnable(GL_LIGHTING);
	}
}
